package com.chixing.controller;


import com.chixing.pojo.Member;
import com.chixing.pojo.Support;
import com.chixing.service.RedisLikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
public class PraiseController {

    @Autowired
    private RedisLikeService redisLikeService;

    //点赞
    @PostMapping("/praise/save")
    public String save2redis(Support support, Integer  supportCount , HttpSession session){
        System.out.println("点赞接收到的praise:" + support);
        System.out.println("点赞后，总点赞数：" +supportCount );
        Member customer =(Member) session.getAttribute("customer");
        Integer memberId = customer.getMemberId();
        System.out.println("当前登录的用户id:" + memberId);
        support.setMemberId(memberId);


        redisLikeService.saveLike2Redis(support,supportCount); // redis --- mysql

        return "save praise success";


    }

    //取消点赞
    @PostMapping("/praise/cancle")
    public String cancle2redis(Support support, Integer  supportCount , HttpSession session){
        System.out.println("取消点赞接收到的praise:" + support);
        System.out.println("取消点赞后，总点赞数：" +supportCount );
        Member customer =(Member) session.getAttribute("customer");
        Integer memberId = customer.getMemberId();
        System.out.println("当前登录的用户id:" + memberId);
        return "cancle praisesuccess";
    }

}
